library(tidyverse)
library(lubridate)
library(mdsr)
library(macleish)
library(ggplot2)
library(plotly)
Question: Using the data whately 2015 from the macleish package,
create an interactive plot using plotly (or ggplotly) displaying time
(in days) on the x-axis and temperature on the y-axis with three lines:
one for the high temperature of the day, one for the average temperature
of the day, and one for the low temperature of the day. A csv version of
the file can be found here: https://www.dropbox.com/s/m2nt50qanpijp0m/whately2015.csv?dl=0
head(whately_2015)
## # A tibble: 6 × 8
## when temperature wind_speed wind_dir rel_humidity pressure
## <dttm> <dbl> <dbl> <dbl> <dbl> <int>
## 1 2015-01-01 00:00:00 -9.32 1.40 225. 54.6 985
## 2 2015-01-01 00:10:00 -9.46 1.51 248. 55.4 985
## 3 2015-01-01 00:20:00 -9.44 1.62 258. 56.2 985
## 4 2015-01-01 00:30:00 -9.3 1.14 244. 56.4 985
## 5 2015-01-01 00:40:00 -9.32 1.22 238. 56.9 984
## 6 2015-01-01 00:50:00 -9.34 1.09 242. 57.2 984
## # ℹ 2 more variables: solar_radiation <dbl>, rainfall <dbl>
g <- whately_2015 %>%
mutate(date = as.Date(when)) %>%
group_by(date) %>%
summarise(
High = max(temperature),
Average = mean(temperature),
Low = min(temperature)
) %>%
pivot_longer(
c(High, Average, Low),
names_to = "type",
values_to = "temp"
) %>% ggplot(
aes(x = date, y = temp, color = type)
) +
geom_line() +
xlab("Date") +
ylab("Temperature") +
labs(color = "Type")
ggplotly(g)